{include file="public/header" /}
<style type="text/css">
    .gray-bg{ background: #fff; }
    .red{color: #d43f3a}
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="wrapper wrapper-content">
        <div class="row">
            <form class="form-horizontal" method="post">
                <div class="col-sm-12" id="form">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">类型：</label>
                        <div class="col-sm-9">
                            <select class="form-control" name="type">
                                <option value="-1">请选择类型...</option>
                                {foreach  $type as $key => $vo}
                                {if !in_array($key, $created_type)}
                                    <option value="{$key}">{$vo.name}</option>
                                {/if}
                                {if isset($data.type) and $data.type eq $key}
                                    <option value="{$key}" selected="selected">{$vo.name}</option>
                                {/if}
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">模板ID：</label>
                        <div class="col-sm-9">
                            <input type="text" name="template_id"  class="form-control" value="{$data.template_id|default=""}" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"></label>
                        <div class="col-sm-9">
                            键根据短信后台填写即可(如：<span class="red">${code} -> code</span> 不需要其他特殊符号)，值可以写入固定值或使用 <span class="red">系统变量</span>
                            <br /><br />
                            <p><span class="red">[date]</span> 日期时间(2020-01-01 12:34:56) <span class="red">[time]</span> 时间(12:34:56) <span class="red">[captcha]</span> 验证码(123456) <span class="red">[nickname]</span> 昵称(犀利哥)</p>
                            <p><span class="red">[other_{i}]</span> {i}替换成1,2，……,n，例如：您的验证码是[other_1]，如非本人操作[other_2]，请勿理会。</p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">参数：</label>
                        <div class="col-sm-9">
                            <a class="btn btn-primary" id="add-item"><i class="fa fa-plus"></i> 添加参数</a>
                        </div>
                    </div>
                    {foreach $tempVal as $key => $vo}
                    <div class="form-group" id="item-{$key}">
                        <label class="col-sm-2 control-label"></label>
                        <div class="col-sm-9">
                            <div class="col-sm-5">
                                <label class="col-sm-1 control-label">键：</label>
                                <div class="col-sm-9">
                                    <input type="text" name="template_value[{$key}][key]" class="form-control" value="{$vo.key}"/>
                                </div>
                            </div>
                            <div class="col-sm-5">
                                <label class="col-sm-1 control-label">值：</label>
                                <div class="col-sm-9">
                                    <input type="text" name="template_value[{$key}][value]" class="form-control" value="{$vo.value}">
                                </div>
                            </div>
                            <a class="btn btn-danger" href="javascript:del_item({$key})"><i class="fa fa-trash"></i> 删除</a>
                        </div>
                    </div>
                    {/foreach}
                </div>
                <input type="hidden" name="id" value="{$data.id|default="0"}" />
            </form>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript">
var id = {:count($tempVal)};
$("#add-item").click(function () {
    var
    html =  '<div class="form-group" id="item-'+id+'">';
    html +=   '<label class="col-sm-2 control-label"></label>';
    html +=   '<div class="col-sm-9">';
    html +=   item(id, '键', 'key');
    html +=   item(id, '值', 'value');
    html +=   '<a class="btn btn-danger" href="javascript:del_item('+id+')"><i class="fa fa-trash"></i> 删除</a>';
    html +=   '</div>';
    html += '</div>';
    $("#form").append(html);
    id++;
});
function item(id, name, key) {
    var
    html =  '<div class="col-sm-5">';
    html +=  '<label class="col-sm-1 control-label">'+name+'：</label>';
    html +=   '<div class="col-sm-9">';
    html +=    '<input type="text" name="template_value['+id+']['+key+']" class="form-control" value="" />';
    html +=   '</div>';
    html += '</div>';
    return html;
}
function del_item(id) {
    $('#form #item-'+id).remove();
}
</script>
{include file="public/bottom" /}